package server.command;

import java.util.List;

import org.apache.mina.core.session.IoSession;

import server.IDispatcher;
import server.Message;
import server.core.User;

public class Quit extends Command {

	private Quit() {
	}

	public static Command getInstance() {
		if (instance == null)
			instance = new Quit();
		return instance;
	}

	@Override
	public synchronized void execute(IoSession session, List<String> parameters, IDispatcher dispatcher) {
		User user = (User) session.getAttribute("user");
		dispatcher.removeSession(user.getUsername());
		session.write(new Message("QUIT", "OK"));
		session.close(true);
	}
}
